import * as crypto from 'crypto';
// import { validate } from 'class-validator';
// import { plainToClass } from 'class-transformer';

export function md5(str: string): string {
  const strWithSuffix = `${str}VPN`;
  const hash = crypto.createHash('md5');
  hash.update(strWithSuffix);
  return hash.digest('hex');
}

export function randomSix(number: number = 6, prefix: string = ''): string {
  const chars: string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  let result: string = '';
  for (let i = 0; i < number; i++) {
    result += chars[Math.floor(Math.random() * chars.length)];
  }
  return `${prefix}${result}`;
}

// export async function plain_toClass(type: any, data: any) {
//   const registerRequest = plainToClass(type, data);
//   const errors = await validate(registerRequest);
//   if (errors.length > 0) {
//     return errors[0].constraints!.matches || errors[0].constraints!.isNotEmpty;
//   }
//   return '';
// }
